setwd("/Users/MaiHassan/Dropbox/Migration_HassanKlaus/Revisions_WorldPolitics/ConditionalAccept")
library(foreign)
library(survival)
library(texreg)

#########################################
#########################################
###############DATASETS##################
#########################################
#########################################
dat <- read.csv("PRGapReplicationData.csv")
autoyears <- dat[dat$mpe==0,]
mpeyears <- dat[which(dat$year>1990),] 
mpeyears.allotbefore <- mpeyears[mpeyears$allocation_year < 1990,]
mpeyears_postelection <- dat[which(dat$year>1992),]

kenyatta <- dat[dat$year<1979,]
kenyatta.auto <- kenyatta[kenyatta$year>1968,]
moi1 <- dat[dat$year>1978,]
moi1 <- moi1[moi1$year<1991,]
moi2 <- mpeyears[mpeyears $moi == 1,]
moifull <- dat[dat$moi == 1,]
moifull.kenyatta_allot <- moifull[moifull$kenyatta_allocation==1,]
kibaki <- mpeyears[mpeyears $moi == 0,]
postviolence <- dat[dat$post_2007==1,]


#########################################
#########################################
###############MAIN TEXT#################
#########################################
#########################################

#########################################
#########################################
###############TABLE 3###################
#########################################
#########################################
mpe.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation, data= dat, method="efron") 
summary(mpe.basic)

moiyears.mpe.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation, data= moifull, method="efron") 
summary(moiyears.mpe.basic)

mpe.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic, data= dat, method="efron") 
summary(mpe.interaction)

moiyears.mpe.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moifull, method="efron") 
summary(moiyears.mpe.interaction)

autocratic.coethnic <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic , data= autoyears, method="efron") 
summary(autocratic.coethnic) 
 
electoral.coethnic <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  , data= mpeyears, method="efron") 
summary(electoral.coethnic)

electoral.swing <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  , data= mpeyears, method="efron") 
summary(electoral.swing) 

electoral.lvs <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic , data= mpeyears_postelection, method="efron") 
summary(electoral.lvs)

texreg(list(mpe.basic,  moiyears.mpe.basic, mpe.interaction, moiyears.mpe.interaction, autocratic.coethnic, electoral.coethnic, electoral.swing, electoral.lvs), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
##############FIGURE 3###################
#########################################
#########################################
newdat.autocratic.coethnic <- data.frame(pres_coethnic_percent_62 = c(0.1,0.9), ln_scheme_size =rep(mean(autoyears$ln_scheme_size),2),ln_road_expenditure = rep(mean(autoyears$ln_road_expenditure),2), ln_settlers =rep(mean(autoyears$ln_settlers),2),  elf_62 = rep(mean(na.omit(autoyears$elf_62)),2), landsminister_coethnic = c(0,0), mp_coethnic = rep(mean(autoyears$mp_coethnic),2))

electoral.coethnic.fig <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic +  landsminister_coethnic  , data= mpeyears, method="efron") 

newdat.electoral.coethnic.fig <- data.frame(pres_coethnic_percent_89 = c(0.1,0.9), ln_scheme_size =rep(mean(mpeyears$ln_scheme_size),2),ln_road_expenditure = rep(mean(na.omit(mpeyears$ln_road_expenditure)),2), ln_settlers =rep(mean(mpeyears$ln_settlers),2),  elf_89 = rep(mean(na.omit(mpeyears$elf_89)),2), mp_coethnic = c(0,0), landsminister_coethnic = c(0,0))

pdf(file="Figure3SurvivalPlots.pdf", height = 6, width = 9)
par(mfrow=c(1,2))

plot(survfit(autocratic.coethnic, newdata= newdat.autocratic.coethnic), xlim = c(0,22),   xlab="Years Since Allocation", ylab="Likelihood of Non-Registration", main="Autocratic Era",  col=c("dodgerblue", "firebrick1"), lty=c("solid", "dashed"), lwd=c(3,3))

plot(survfit(electoral.coethnic.fig, newdata= newdat.electoral.coethnic.fig), lwd=c(3,3), lty=c("solid","dashed"), ylab="", xlab="Years Since Allocation During Electoral Era", main="Electoral Era",  col=c("dodgerblue", "firebrick1"), xlim=c(0,22))
legnames <- c("10% Coethnic", "90% Coethnic")

legend("topright", legnames, lty = c("solid","dashed"), col = c("dodgerblue", "firebrick1"), lwd=c(3,3), bty = "n")
dev.off()


#########################################
#########################################
###############TABLE 4###################
#########################################
#########################################
kenyatta.maumau.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~     ln_scheme_size   + ln_road_expenditure     + ln_settlers  + elf_62    + landsminister_coethnic + mp_coethnic + gsu_officers, data= kenyatta.auto, method="efron") 
summary(kenyatta.maumau.basic)

kenyatta.maumau.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_62  +  ln_scheme_size   + ln_road_expenditure     + ln_settlers  + elf_62    + landsminister_coethnic + mp_coethnic + pres_coethnic_percent_62 *gsu_officers , data= kenyatta.auto, method="efron") 
summary(kenyatta.maumau.interaction)

moi.immediate.postcoup.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~  immediate_post_coup  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moi1, method="efron") 
summary(moi.immediate.postcoup.basic)

moi.immediate.postcoup.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~  immediate_post_coup* pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moi1, method="efron") 
summary(moi.immediate.postcoup.interaction)

moi.postcoup.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~  post_coup  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moi1, method="efron") 
summary(moi.postcoup.basic)

moi.postcoup.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~  post_coup * pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moi1, method="efron") 
summary(moi.postcoup.interaction)

moi.outsider <- coxph(Surv(starttime, timeid, indicator_registration) ~  ln_scheme_size   + elf_89   + landsminister_coethnic  +   ln_settlers  + pres_coethnic_percent_89* outsider_percent_89 + years_since_allocation + elf_89 + ln_road_expenditure+ mp_coethnic+ landsminister_coethnic , data= moi2, method="efron") 
summary(moi.outsider)

kibak.postviolence.outsider <- coxph(Surv(starttime, timeid, indicator_registration) ~   pres_coethnic_percent_89 * outsider_percent_89    +ln_scheme_size  + elf_89   + landsminister_coethnic + years_since_allocation + ln_settlers + elf_89  + mp_coethnic + ln_road_expenditure , data= postviolence, method="efron") 
summary(kibak.postviolence.outsider)

electoral.electionyear.basic <- coxph(Surv(starttime, timeid, indicator_registration) ~  election_run_up + pres_coethnic_percent_89  + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure , data= mpeyears, method="efron") 
summary(electoral.electionyear.basic) 

electoral.electionyear.interaction <- coxph(Surv(starttime, timeid, indicator_registration) ~  election_run_up* swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure , data= mpeyears, method="efron") 
summary(electoral.electionyear.interaction) 

texreg(list(kenyatta.maumau.basic, kenyatta.maumau.interaction, moi.immediate.postcoup.basic, moi.immediate.postcoup.interaction, moi.postcoup.basic, moi.postcoup.interaction, moi.outsider, kibak.postviolence.outsider, electoral.electionyear.basic, electoral.electionyear.interaction), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))


#########################################
#########################################
###############APPENDIX##################
#########################################
#########################################


#########################################
#########################################
###############TABLE 2###################
#########################################
#########################################
moiyears.mpe.basic.otheralloter <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation, data= moifull.kenyatta_allot , method="efron") 
summary(moiyears.mpe.basic.otheralloter)

moiyears.mpe.interaction.otheralloter <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic, data= moifull.kenyatta_allot , method="efron") 
summary(moiyears.mpe.interaction.otheralloter)

electoral.coethnic.otheralloter <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic , data= mpeyears.allotbefore , method="efron") 
summary(electoral.coethnic.otheralloter)

electoral.swing.otheralloter <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  , data= mpeyears.allotbefore, method="efron") 
summary(electoral.swing.otheralloter) 

electoral.lvs.otheralloter <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  pres_vs_lagged + years_since_allocation + landsminister_coethnic + mp_coethnic , data= mpeyears.allotbefore, method="efron") 
summary(electoral.lvs.otheralloter)


#texreg(list(moiyears.mpe.basic.otheralloter, moiyears.mpe.interaction.otheralloter, electoral.coethnic.otheralloter, electoral.swing.otheralloter, electoral.lvs.otheralloter), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
###############TABLE 3###################
#########################################
#########################################
mpe.basic.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ value_cashcrops, data= dat, method="efron") 
summary(mpe.basic.cc)

moiyears.mpe.basic.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ value_cashcrops, data= moifull, method="efron") 
summary(moiyears.mpe.basic.cc)

mpe.interaction.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic+ value_cashcrops, data= dat, method="efron") 
summary(mpe.interaction.cc)

moiyears.mpe.interaction.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic+ value_cashcrops, data= moifull, method="efron") 
summary(moiyears.mpe.interaction.cc)

autocratic.coethnic.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + value_cashcrops, data= autoyears, method="efron") 
summary(autocratic.coethnic.cc) 
 
electoral.coethnic.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + value_cashcrops, data= mpeyears, method="efron") 
summary(electoral.coethnic.cc)

electoral.swing.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  + value_cashcrops, data= mpeyears, method="efron") 
summary(electoral.swing.cc) 

electoral.lvs.cc <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + value_cashcrops, data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.cc)

texreg(list(mpe.basic.cc,  moiyears.mpe.basic.cc, mpe.interaction.cc, moiyears.mpe.interaction.cc, autocratic.coethnic.cc, electoral.coethnic.cc, electoral.swing.cc, electoral.lvs.cc), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
###############TABLE 4###################
#########################################
#########################################
mpe.basic.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ perctent_highpotential, data= dat, method="efron") 
summary(mpe.basic.hp)

moiyears.mpe.basic.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ perctent_highpotential, data= moifull, method="efron") 
summary(moiyears.mpe.basic.hp)

mpe.interaction.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic+ perctent_highpotential, data= dat, method="efron") 
summary(mpe.interaction.hp)

moiyears.mpe.interaction.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic+ perctent_highpotential, data= moifull, method="efron") 
summary(moiyears.mpe.interaction.hp)

autocratic.coethnic.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + perctent_highpotential, data= autoyears, method="efron") 
summary(autocratic.coethnic.hp) 
 
electoral.coethnic.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + perctent_highpotential, data= mpeyears, method="efron") 
summary(electoral.coethnic.hp)

electoral.swing.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  + perctent_highpotential, data= mpeyears, method="efron") 
summary(electoral.swing.hp) 

electoral.lvs.hp <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + perctent_highpotential, data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.hp)

texreg(list(mpe.basic.hp,  moiyears.mpe.basic.hp, mpe.interaction.hp, moiyears.mpe.interaction.hp, autocratic.coethnic.hp), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
###############TABLE 5###################
#########################################
#########################################
mpeyears$largergroup89_perc <- ifelse(mpeyears$moi == 1, mpeyears$kalenjin_maasai_percent_89, mpeyears$kikuyu_meru_percent_89)
electoral.coethnic.broader <- coxph(Surv(starttime, timeid, indicator_registration) ~  largergroup89_perc +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  , data= mpeyears, method="efron") 
summary(electoral.coethnic.broader)

moi.coethnic.broader <- coxph(Surv(starttime, timeid, indicator_registration) ~  kalenjin_maasai_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  , data= moi2, method="efron") 
summary(moi.coethnic.broader )

kibaki.coethnic.broader <- coxph(Surv(starttime, timeid, indicator_registration) ~  kikuyu_meru_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  , data= kibaki, method="efron") 
summary(kibaki.coethnic.broader )

texreg(list(electoral.coethnic.broader, moi.coethnic.broader, kibaki.coethnic.broader), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))


#########################################
#########################################
###############TABLE 6###################
#########################################
#########################################
mpe.basic.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ dc_coethnic + ln_km_to_district_capital, data= dat, method="efron") 
summary(mpe.basic.sc)

moiyears.mpe.basic.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ dc_coethnic + ln_km_to_district_capital, data= moifull, method="efron") 
summary(moiyears.mpe.basic.sc)

mpe.interaction.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic+ dc_coethnic + ln_km_to_district_capital, data= dat, method="efron") 
summary(mpe.interaction.sc)

moiyears.mpe.interaction.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic+ dc_coethnic + ln_km_to_district_capital, data= moifull, method="efron") 
summary(moiyears.mpe.interaction.sc)

autocratic.coethnic.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + dc_coethnic + ln_km_to_district_capital, data= autoyears, method="efron") 
summary(autocratic.coethnic.sc) 
 
electoral.coethnic.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + dc_coethnic + ln_km_to_district_capital, data= mpeyears, method="efron") 
summary(electoral.coethnic.sc)

electoral.swing.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  + dc_coethnic + ln_km_to_district_capital, data= mpeyears, method="efron") 
summary(electoral.swing.sc) 

electoral.lvs.sc <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + dc_coethnic + ln_km_to_district_capital, data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.sc)

texreg(list(mpe.basic.sc,  moiyears.mpe.basic.sc, mpe.interaction.sc, moiyears.mpe.interaction.sc, autocratic.coethnic.sc, electoral.coethnic.sc, electoral.swing.sc, electoral.lvs.sc), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
###############TABLE 7###################
#########################################
#########################################
mpe.basic.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe       +  ln_road_expenditure  +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ scheme_density, data= dat, method="efron") 
summary(mpe.basic.sd)

moiyears.mpe.basic.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe        +  ln_road_expenditure    + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ scheme_density, data= moifull, method="efron") 
summary(moiyears.mpe.basic.sd)

mpe.interaction.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62        +  ln_road_expenditure   + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic+ scheme_density, data= dat, method="efron") 
summary(mpe.interaction.sd)

moiyears.mpe.interaction.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62        +  ln_road_expenditure   + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic+ scheme_density, data= moifull, method="efron") 
summary(moiyears.mpe.interaction.sd)

autocratic.coethnic.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62         +  ln_road_expenditure    + elf_62   + landsminister_coethnic  + mp_coethnic + scheme_density, data= autoyears, method="efron") 
summary(autocratic.coethnic.sd) 
 
electoral.coethnic.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89       +  ln_road_expenditure    + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + scheme_density, data= mpeyears, method="efron") 
summary(electoral.coethnic.sd)

electoral.swing.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89   + mp_coethnic + landsminister_coethnic + years_since_allocation   + ln_road_expenditure  + scheme_density, data= mpeyears, method="efron") 
summary(electoral.swing.sd) 

electoral.lvs.sd <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89        +  ln_road_expenditure    + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + scheme_density, data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.sd)

texreg(list(mpe.basic.sd,  moiyears.mpe.basic.sd, mpe.interaction.sd, moiyears.mpe.interaction.sd, autocratic.coethnic.sd, electoral.coethnic.sd, electoral.swing.sd, electoral.lvs.sd), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))



#########################################
#########################################
###############TABLE 8###################
#########################################
#########################################
mpe.basic.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ year, data= dat, method="efron") 
summary(mpe.basic.ltt)

moiyears.mpe.basic.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ year, data= moifull, method="efron") 
summary(moiyears.mpe.basic.ltt)

mpe.interaction.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~   mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62    + years_since_allocation  + landsminister_coethnic + mp_coethnic+ year, data= dat, method="efron") 
summary(mpe.interaction.ltt)

moiyears.mpe.interaction.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe * pres_coethnic_percent_62 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers  + pres_coethnic_percent_62 + elf_62  + landsminister_coethnic  + years_since_allocation + mp_coethnic+ year, data= moifull, method="efron") 
summary(moiyears.mpe.interaction.ltt)

autocratic.coethnic.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + year, data= autoyears, method="efron") 
summary(autocratic.coethnic.ltt) 
 
electoral.coethnic.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + year, data= mpeyears, method="efron") 
summary(electoral.coethnic.ltt)

electoral.swing.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  + year, data= mpeyears, method="efron") 
summary(electoral.swing.ltt) 

electoral.lvs.ltt <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + year, data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.ltt)

texreg(list(mpe.basic.ltt,  moiyears.mpe.basic.ltt, mpe.interaction.ltt, moiyears.mpe.interaction.ltt, autocratic.coethnic.ltt, electoral.coethnic.ltt, electoral.swing.ltt, electoral.lvs.ltt), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))

#########################################
#########################################
###############TABLE 9###################
#########################################
#########################################
mpe.basic.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size      +  ln_road_expenditure + ln_settlers +   mp_coethnic + landsminister_coethnic + elf_62 + years_since_allocation+ frailty(district_89, distribution="gaussian"), data= dat, method="efron") 
summary(mpe.basic.ft)

moiyears.mpe.basic.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~  mpe +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + years_since_allocation+ frailty(district_89, distribution="gaussian"), data= moifull, method="efron") 
summary(moiyears.mpe.basic.ft)

autocratic.coethnic.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~ pres_coethnic_percent_62  +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_62   + landsminister_coethnic  + mp_coethnic + frailty(district_89, distribution="gaussian"), data= autoyears, method="efron") 
summary(autocratic.coethnic.ft) 
 
electoral.coethnic.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_coethnic_percent_89+  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +  mp_coethnic + years_since_allocation +  landsminister_coethnic  + frailty(district_89, distribution="gaussian"), data= mpeyears, method="efron") 
summary(electoral.coethnic.ft)

electoral.swing.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~   swing_percent_89   + elf_89 +ln_scheme_size  + mp_coethnic + landsminister_coethnic + years_since_allocation + ln_settlers  + ln_road_expenditure  + frailty(district_89, distribution="gaussian"), data= mpeyears, method="efron") 
summary(electoral.swing.ft) 

electoral.lvs.ft <- coxph(Surv(starttime, timeid, indicator_registration) ~  pres_vs_lagged  + pres_coethnic_percent_89 +  ln_scheme_size       +  ln_road_expenditure + ln_settlers   + elf_89  +   years_since_allocation + landsminister_coethnic + mp_coethnic + frailty(district_89, distribution="gaussian"), data= mpeyears_postelection, method="efron") 
summary(electoral.lvs.ft)

texreg(list(mpe.basic.ft,  moiyears.mpe.basic.ft, autocratic.coethnic.ft, electoral.coethnic.ft, electoral.swing.ft, electoral.lvs.ft), include.rsquared = TRUE, include.maxrs = TRUE, stars = c(0.001, 0.01, 0.05, 0.1))




